package com.hyj.ecp.clientservice.cust.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Service;

import com.ecp.cust.ClientUserQO;
import com.ecp.cust.CustAddressee;
import com.ecp.cust.CustProblem;
import com.hyj.ecp.clientservice.cust.service.IClientLoginService;

@Service
public class ClientLoginService implements IClientLoginService {

	@Resource(name="sqlSession")
    public  SqlSessionTemplate sqlSession;

	@Override
	public ClientUserQO login(ClientUserQO qo) {
		
		ClientUserQO u = (ClientUserQO) sqlSession.selectOne("com.ecp.client.cust.login",qo);
		return  u;
	}

	@Override
	public int saveUser(ClientUserQO qo) {
		// 验证账户重复
		int anum = sqlSession.selectOne("com.ecp.client.cust.queryAccount", qo);
		if (anum > 0) {
			return 1;
		}

		int a = sqlSession.insert("com.ecp.client.cust.register", qo);

		if (a > 0) {
			return 0;
		}
		return 999;
	}

	@Override
	public int updateUser(ClientUserQO qo) {
		int a = sqlSession.update("com.ecp.client.cust.updateUser", qo);
		if (a > 0) {
			return 0;
		}
		return 999;
	}

	@Override
	public int saveCustAddr(CustAddressee qo) {
		int a = sqlSession.insert("com.ecp.client.cust.insertCustAddr", qo);
		if (a > 0) {
			return 0;
		}
		return 999;
	}

	@Override
	public int updateCustAddr(CustAddressee qo) {
		int a = sqlSession.insert("com.ecp.client.cust.updateCustAddr", qo);
		if (a > 0) {
			return 0;
		}
		return 999;
	}

	@Override
	public List<Map<String, Object>> queryCustAddr(CustAddressee qo) {
		List<Map<String, Object>> list = sqlSession.selectList("com.ecp.client.cust.queryCustAddr", qo);
		return list;
	}

	@Override
	public int saveCustProblem(CustProblem qo) {
		return   sqlSession.insert("com.ecp.client.cust.saveCustProblem", qo);
	}

	@Override
	public int deleteCustAddr(CustAddressee qo) {
		int a = sqlSession.delete("com.ecp.client.cust.deleteCustAddr", qo);
		if (a > 0) {
			return 0;
		}
		return 999;
	}
}
